package com.hyk.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyk.entity.Product;
import com.hyk.entity.request.ProductRequest;
import com.hyk.entity.response.ProductResponse;
import com.hyk.mapper.ProductMapper;
import com.hyk.service.IProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;

/**
 * <p>
 * 商品表 服务实现类
 * </p>
 *
 * @author hyk
 * @since 2021-03-18
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    @Resource
    ProductMapper productMapper;

    @Override
    public IPage<ProductResponse> findListForName(ProductRequest request) {
        IPage<ProductResponse> productResponseIPage = new Page<>(request.getPage(),request.getSize());
        IPage<ProductResponse> page = productMapper.findListForName(productResponseIPage,request);
        return page;
    }

    @Override
    public void upOrDown(Long id) {
        Product product = productMapper.selectById(id);
        if (product.getProductStatus() == 0){
            product.setProductStatus(1);
        }else{
            product.setProductStatus(0);
        }
        productMapper.updateById(product);
    }
}
